# -*- coding: utf-8 -*-
# @Time    : 2022/7/15 21:44
# @Author  : vvh
# @Email   : 2647167477@qq.com
# @File    : goods_page.py
# @Software: PyCharm
from selenium.webdriver.common.by import By
from pages.base_pageage import BasePage

class GoodsPage(BasePage):
    """产品页类"""
    # 产品页定位器
    add_goods_btn_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(2) > div.pull-right > a')
    new_add_good_name = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(3) > a > span')
    del_good_input_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input')
    delete_locator = (By.CSS_SELECTOR,'#delete')

    def switch_add_good_page(self):
        """点击进入产品添加页"""
        self.goods_page = BasePage(self.driver)
        self.goods_page.find(self.add_goods_btn_locator).click()

    def del_good(self):
        """删除商品"""
        self.goods_page.find(self.del_good_input_locator).click()
        self.goods_page.find(self.delete_locator).click()
        self.driver.switch_to.alert.accept()

    def get_new_add_good_name(self):
        """获取新添加的产品名称"""
        return self.goods_page.find(self.new_add_good_name).text